﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Photon.SocketServer;
using WorldOfSuperpowers.Cache;
using WorldOfSuperpowers_COMMON;
using WorldOfSuperpowers_COMMON.DataModel;

namespace WorldOfSuperpowers.Handler
{
    public class RenameHandler:BaseHandler
    {
        public override void InitCode()
        {
            code = OperationCode.Rename;
        }

        public override void TranslateDic(Dictionary<byte, object> message, MasterClientPeer peer, SendParameters sendParameters)
        {
            object UserData = GetValueFromDic(code, message);
            if (UserData!= null)
            {
                OperationResponse op = new OperationResponse();
                op.OperationCode = (byte)code;
                UserDataModel Umodel = ProtoTranslater.GetInstance().GetTypeFromBytes<UserDataModel>(UserData);
                bool isSuccess = UserCache.RenameAction(Umodel);
                op.DebugMessage = isSuccess ? "命名成功" : "该名字已注册";
                op.ReturnCode = isSuccess ? (byte)ReturnCode.Success : (byte)ReturnCode.Fail;
                peer.SendOperationResponse(op, sendParameters);
                MasterServer.log.Debug("账号注册结果:"+ isSuccess+",发送反馈消息类型:"+code);
            }
        }
    }
}
